<% content_for :page_title do %>
  <%= page_header_back_button spree.edit_admin_order_path(@order) %>

  <div class="d-flex gap-3 align-items-center">
    <%= @return_authorization.number %>

    <span class="badge badge-<%= @return_authorization.state %>">
      <%= Spree.t("return_authorization_states.#{@return_authorization.state}") %>
    </span>
  </div>
<% end %>

<%= render partial: "spree/admin/shared/error_messages",
locals: {
  target: @return_authorization,
} %>

<%= form_for [:admin, @order, @return_authorization] do |f| %>
  <%= render partial: "form", locals: { f: f } %>

  <div class="form-actions">
    <%= turbo_save_button_tag Spree.t("actions.update") %>
    <div class="ml-auto d-flex gap-3">
      <% if f.object.can_cancel? && can?(:cancel, f.object) %>
        <%= link_to Spree.t("actions.cancel"),
        spree.cancel_admin_return_authorization_path(f.object),
        class: "btn btn-danger",
        data: {
          turbo_method: :patch,
          turbo_confirm: Spree.t(:are_you_sure),
        } %>
      <% end %>
      <% if f.object.can_be_deleted? && can?(:delete, f.object) %>
        <%= link_to Spree.t("actions.destroy"),
        spree.admin_return_authorization_path(f.object),
        data: {
          turbo_method: :delete,
          turbo_confirm: Spree.t(:are_you_sure_delete),
        },
        class: "btn btn-danger" %>
      <% end %>
    </div>
  </div>
<% end %>
